package tech.aistar.day05.filters;

import javax.servlet.*;
import javax.servlet.annotation.WebServlet;
import java.io.IOException;
//@WebServlet(urlPatterns = "/*")
public class MyFilter implements Filter {
    /**
     * 过滤器何时被初始化 - 容器启动的时候会初始化该Filter对象
     * 并且立即调用init方法
     * @param filterConfig
     * @throws ServletException
     */
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        System.out.println("Filter...-init");
    }

    /**
     * 过滤链
     * @param servletRequest
     * @param servletResponse
     * @param filterChain
     * @throws IOException
     * @throws ServletException
     */
    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        System.out.println("filter - doFilter...");

        //允许继续向下执行的.
        filterChain.doFilter(servletRequest,servletResponse);
    }

    @Override
    public void destroy() {
        System.out.println("destroy...");
    }
}
